//package org.springblade.mq.rabbit.handler;
//
//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.springblade.core.tool.jackson.JsonUtil;
//import org.springblade.modules.material.bo.StudentAnswerBO;
//import org.springblade.modules.material.controller.AnswerController;
//import org.springblade.mq.rabbit.constant.RabbitConstant;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//
//
///**
// * 延迟队列处理器
// *
// * @author yangkai.shen
// */
//@Slf4j
//@Component
//@RabbitListener(queues = RabbitConstant.DELAY_QUEUE)
//public class DelayQueueHandler {
//
//	@Autowired
//	private AnswerController answerController;
//
//	@RabbitHandler
//	public void directHandlerManualAck(String msgBody, Message message, Channel channel) {
//		//  如果手动ACK,消息会被监听消费,但是消息在队列中依旧存在,如果 未配置 acknowledge-mode 默认是会在消费完毕后自动ACK掉
//		final long deliveryTag = message.getMessageProperties().getDeliveryTag();
//		try {
//			log.info("延迟队列，手动ACK，接收消息：{}", JsonUtil.toJson(msgBody));
//			StudentAnswerBO result = JsonUtil.parse(msgBody, StudentAnswerBO.class);
//			result.getAnswerEntity().setStatus(1);
//			if (CollectionUtils.isEmpty(result.getAnswerOptionList()) || result.getAnswerEntity().getStatus() == 0) {
//				//如果列表不为空和仍未交卷则直接保存试卷
//				answerController.saveStudentAnswer(result);
//				channel.basicAck(deliveryTag, false);
//				return;
//			}
//			answerController.update(result.getAnswerEntity());
//			// 通知 MQ 消息已被成功消费,可以ACK了
//			channel.basicAck(deliveryTag, false);
//		} catch (IOException e) {
//			try {
//				// 处理失败,重新压入MQ
//				channel.basicRecover();
//			} catch (IOException e1) {
//				e1.printStackTrace();
//			}
//		}
//	}
//}
